﻿using Sms.TencentSms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sms
{
    public class TecentSmsControl
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="phoneNumList">电话前必须加上 +86 否则会提示国家或号码错误</param>
        /// <param name="sign"></param>
        /// <param name="templateID"></param>
        /// <param name="templateParam"></param>
        /// <returns></returns>
        public SendSmsResponse SendSms(string[] phoneNumList, string sign, string templateID, string[] templateParam)
        {
            //SendSmsResponse testResp = new SendSmsResponse();
            //testResp.RequestId = "测试发送成功";
            //testResp.SendStatusSet = new SendStatus[10];
            //return testResp;

            try
            {
                Credential cred = new Credential
                {
                    SecretId = TencentSmsHelper.SecretId,
                    SecretKey = TencentSmsHelper.SecretKey
                };

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = ("sms.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                SmsClient client = new SmsClient(cred, "", clientProfile);
                SendSmsRequest req = new SendSmsRequest();
                req.SmsSdkAppid = TencentSmsHelper.SmsSdkAppid;

                req.PhoneNumberSet = phoneNumList;// new string[] { "+86" }; 
                req.TemplateParamSet = templateParam;// new string[] { "1111", "3" };
                req.TemplateID = templateID;
                req.Sign = sign;
                SendSmsResponse resp = client.SendSmsSync(req);
                Console.WriteLine(AbstractModel.ToJsonString(resp));

                return resp;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.Read();

            return null;
        }
    }
}
